﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SAP.WebServices;
using System.Data;
using ReadXMLFile;
using System.Collections;
using System.Globalization;
using System.Text.RegularExpressions;
namespace SAP
{
    public partial class Popup_ViewApproval : System.Web.UI.Page
    {
        public static DataTable dtContents;
        public static DataTable dtHeader;
        private GeneralFunctions GF ;
         int RequestID = -1;
        int viewMode = 0;
        static String EmpID;
        private LoginSession CurrentLoginSession;
        static int reqStatus;
        private string GIAct = "6002001039";
        protected void Page_Load(object sender, EventArgs e)
        {
            SessionCheck();
            //lvContents.Items[0].Visible = false;
            this.RequestID = Request.QueryString["requestID"] == null ? -1 : Request.QueryString["requestID"] == "" ? -1 : Int32.Parse(Request.QueryString["requestID"]);

            if (!IsPostBack)
            {
                //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "ShowLoading", "Dialog.showLoader();", true);

                dtHeader = GF.ObjectSelect("usp_OffHeader_Select", "@hdrID", RequestID.ToString());
                if (dtHeader.Rows.Count == 0)
                    return;

                //if (CurrentLoginSession.UserEmpID != dtHeader.Rows[0]["Manager_EmpID"].ToString() && viewMode==0)
                //{
                //    Response.Redirect("SessionErrorPage.aspx");
                //}

                reqStatus = Int32.Parse(dtHeader.Rows[0]["Status"].ToString());
                if (reqStatus == 0 || reqStatus == 1) //rejected or approved
                { 
                }
            
               // hf_XMLString.Value = xmlStr;
                xmlObj xmlObject = new xmlObj();

                lb_ReqNumber.Text = dtHeader.Rows[0]["hdrID"].ToString();
                EmpID = dtHeader.Rows[0]["EmpID"].ToString();

                //1. header
                //dtHeader = xmlObject.xmlStr2Ds(xmlStr).Tables[0];
                //if (!dtHeader.Columns.Contains("U_POSTxNo"))
                //    dtHeader.Columns.Add("U_POSTxNo");


                lb_RequestName.Text = dtHeader.Rows[0]["ReqName"].ToString();

                lb_ReqDate.Text = DateTime.Parse(dtHeader.Rows[0]["ReqDate"].ToString()).ToString("dd/MM/yyyy");

                lb_ReqType.Text = getRequestTypeName(dtHeader.Rows[0]["ReqType"].ToString());                             
                
                //2. detail                
                dtContents = GF.ObjectSelect("usp_OffDetail_Select", "@hdrID", RequestID.ToString());//GF.ConvertDataTable_RemoveCols(, KeepColumsContent);

                lb_FromStore.Text = dtHeader.Rows[0]["DefaultWhsName"].ToString();

                if (dtContents.Rows.Count > 0)
                    lb_ToStore.Text = dtContents.Rows[0]["WhsName"].ToString();

                this.lvContents.DataSource = dtContents;
                this.lvContents.DataBind();
            }
        }
        private string getRequestTypeName(string reqType) {
            string typeName = reqType=="F"?"Food Request":(reqType=="B"?"Beverage Request":(reqType=="P"?"Purchase Request":"Food Transfer"));
            return typeName;
        }

        public void SessionCheck()
        {

            if (Session["LoginSession"] != null)
            {
                this.CurrentLoginSession = (LoginSession)Session["LoginSession"];
                GF = new GeneralFunctions(CurrentLoginSession.UserName);
            }
            else
            {
                Response.Redirect("SessionErrorPage.aspx");
            }

        }    
    }
}